package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: AddressBookMapper
 * Package: com.sky.mapper
 * Description:
 *
 * @Author 那啥啥
 * @Create 2024/3/19  13:59
 * @Version 1.0
 */
@Mapper
public interface AddressBookMapper {
    void insert(AddressBook addressBook);

    /**
     * 查询所有地址
     * @return
     */
    List<AddressBook> list(AddressBook addressBook);

    /**
     * 根据id查询地址簿信息
     * @param id
     * @return
     */
    @Select("select *from address_book where  id = #{id}")
    AddressBook getById(Long id);

    /**
     * 根据id修改地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 根据userId设置所有地址为非默认
     */
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateByUserId(AddressBook addressBook);

    /**
     *      * 根据id删除
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
